package com.weixin.cp.config;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import ops.weixin.cp.api.WxCpService;
import ops.weixin.cp.api.impl.WxCpServiceImpl;
import ops.weixin.cp.config.impl.WxCpDefaultConfigImpl;

/**
 * 路由企业微信事件，可根据需求扩展
 * 
 * @author SuM
 * @date: 2019年12月23日下午4:49:02
 */
@Component
public class WxCpConfiguration {
	
	private static WxCpProperties cpProperties;

	private static WxCpService cpService;

	@Autowired
	public WxCpConfiguration(WxCpProperties cpProperties) {
		WxCpConfiguration.cpProperties = cpProperties;
	}

	public static WxCpService getCpService() {
		return cpService;
	}

	public static WxCpProperties getWxCpProperties() {
		return cpProperties;
	}

	@PostConstruct
	public void initServices() {
		WxCpDefaultConfigImpl configStorage = new WxCpDefaultConfigImpl();
		configStorage.setCorpId(WxCpConfiguration.cpProperties.corpId);

		configStorage.setAgentId(WxCpConfiguration.cpProperties.agentId);
		configStorage.setCorpSecret(WxCpConfiguration.cpProperties.secret);
		configStorage.setToken(WxCpConfiguration.cpProperties.token);
		configStorage.setAesKey(WxCpConfiguration.cpProperties.aesKey);
		cpService = new WxCpServiceImpl();
		cpService.setWxCpConfigStorage(configStorage);
	}
}
